﻿@model IEnumerable<Qu.SeniorProject.Model.EvaluationDetail>

@section head {
    <style type="text/css">
        .category
        {
            font-weight: bold; font-size: large; color: #800000;
        }
        .criteriaTitle
        {
            font-weight: bold; font-size: medium; color: #3333FF;
        }
        /*default td */
        td {
          background-color:#FFF;
          border:1px solid black;
          padding:5px;
        }

        .table
        {
            width: 100%;
        }
        .textBoxStyle
        {
            width: 100%;
            border:1px solid blue;
        }
        .col1
        {
            width: 60%;
            background-color:#FFF;
            border:1px solid black;
            padding:5px;
        }
        .col2
        {
            width: 10%;
            background-color:#FFF;
            border:1px solid black;
            padding:5px;
        }
        .col3
        {
            width: 35%;
            background-color:#FFF;
            border:1px solid black;
            padding:5px;
        }

        textarea 
        {
          display: block;
          width:100%;
          height:100%;
          border:1px solid blue;
        }
        label { width: 10em; float: left; }
        label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
        p { clear: both; }
        .submit { margin-left: 12em; }
        em { font-weight: bold; padding-right: 1em; vertical-align: top; color: red; }
        </style>

         <script type="text/javascript">
             $(function () {
                 $("#accordion").accordion({
                     collapsible: true,
                     autoHeight: false,
                     navigation: true
                 });

                 $(".category").filter(":first").click();
                 $(".student1").css("background", "LightYellow");
                 $(".student2").css("background", "AliceBlue");
                 $(".student3").css("background", "Cornsilk");
             });

             $(function () {
                 $("#toggleAccordion").click(function () {
                     if ($(this).text() == 'Click here to Disable Grouping') {
                         $("#accordion").accordion("destroy");
                     }
                     else {
                         $("#accordion").accordion({
                             collapsible: true,
                             autoHeight: false,
                             navigation: true
                         });
                         $(".category").filter(":first").click();
                     }
                     $(this).text($(this).text() == 'Click here to Disable Grouping' ? 'Click here to Enable Grouping' : 'Click here to Disable Grouping');
                 })
             });

             $(function () {
                 $("#submitButton").click(function () {
                     $("#accordion").accordion("destroy");
                     $("#toggleAccordion").text('Click here to Enable Grouping');
                 })
             });

//             jQuery(document).ready(function () {
//                 $('.accordion .head').click(function () {
//                     $(this).next().toggle('slow');
//                     return false;
//                 }).next().hide();
//             });
          </script>
    
@*      <script type="text/javascript">
          $(document).ready(function () {
              $("#GradingForm").validate();
          });
      </script>*@

}

@{ 
    bool isExaminationTime = false;

    //Make the grading mondatory at the time of demo/presentation
    if (ViewBag.ProjectSummary.DemoDateTime != null && ((DateTime)ViewBag.ProjectSummary.DemoDateTime).AddMinutes(-30) <= DateTime.Now)
    {
        isExaminationTime = true;
    }
    else if (ViewBag.ProjectSummary.DemoDateTime == null && ViewBag.ProjectSummary.PresentationDateTime != null && ((DateTime)ViewBag.ProjectSummary.PresentationDateTime).AddMinutes(-30) <= DateTime.Now)
    {
        isExaminationTime = true;
    }
 }

@{
    ViewBag.Title = "Project Grading";
}

<h2>Project Grading</h2>

@using (Html.BeginForm("Grading", "Grading", FormMethod.Post, new { id = "GradingForm" }))
{
    if (ViewBag.EvaluationID != null)
    {
        <input type="hidden" id="evaluationID" name="evaluationID" value="@((int)ViewBag.EvaluationID)" />
    }
    
    <input type="hidden" id="gradingType" name="gradingType" value="@((string)ViewBag.GradingType)" />
    <input type="hidden" id="projectID" name="projectID" value="@((int)ViewBag.ProjectID)" />
    <input type="hidden" id="facultyID" name="facultyID" value="@((string)ViewBag.UserInfo.UserID)" />
    <input type="hidden" id="facultyRole" name="facultyRole" value="@((string)ViewBag.ProjectSummary.Role)" />
    <input type="hidden" id="oldIsNominatedByExaminer1" name="oldIsNominatedByExaminer1" value="@(ViewBag.ProjectSummary.IsNominatedByExaminer1)" />
    <input type="hidden" id="oldIsNominatedByExaminer2" name="oldIsNominatedByExaminer2" value="@(ViewBag.ProjectSummary.IsNominatedByExaminer2)" />

    @DisplayProjectSummary()
    
    <div><p><b>Click the headers to expand/collapse the content of each section. </b><a href="#" id="toggleAccordion">Click here to Disable Grouping</a></p></div>
    <div id="accordion">

       @{string previousCategoryDescription = string.Empty;}
       @foreach (var evaluationDetail in Model)
       {

           //Show the Category Row
           if (previousCategoryDescription != evaluationDetail.CategoryDescription)
           {
                @DisplayCategoryHeader(evaluationDetail.CategoryDescription, evaluationDetail.CategoryDisplayOrder, evaluationDetail.CssStyle)
                <div>
                    <table class="table">
                        @DisplayCategoryDetails(evaluationDetail.CategoryDescription, isExaminationTime)
                    </table>
                </div>

           }
           previousCategoryDescription = evaluationDetail.CategoryDescription;
       }

     </div>
      
       @DisplayGradingFooter(isExaminationTime)

}
           
@*           if (previousCategoryDescription != evaluationDetail.CategoryDescription)
           {

                <h3 class='category'><a href="#">
                    @evaluationDetail.CategoryDisplayOrder. @evaluationDetail.CategoryDescription
                </a></h3>
                <div>
                <table class="table">*@
           
@*             <tr>
                <td colspan="2" class="col1">
                    <div class='category'>@evaluationDetail.CategoryDisplayOrder. @evaluationDetail.CategoryDescription
                    </div>
                </td>
                <td class="col3">
                    <div style="font-weight: bold; color: #800000;"><samll>Comments & feedback</samll></div>
                </td>
            </tr>
           }*@



@helper DisplayCategoryHeader(string categoryDescription, int? categoryDisplayOrder, string ccsStyle)
    {
                <h3 class='@ccsStyle'><a href="#">
                    @categoryDisplayOrder. @categoryDescription
                </a></h3>
    }

@helper DisplayCategoryDetails(string categoryDescription, bool isExaminationTime)
    {
        var requiredField = new Dictionary<string, object>();

        //bool isExaminationDate = true;

        if (isExaminationTime)
        {
            requiredField.Add("class", "required");
        }

        var evaluationDetails = Model.Where(e => e.CategoryDescription == categoryDescription);

        foreach (var evaluationDetail in evaluationDetails)
        {
                    <tr>
                    <td class="col1">
                       <text>
                            <div class='criteriaTitle'>
                                @evaluationDetail.Title 
                                @if (evaluationDetail.IsForGrading)
                                {
                                    <small>(out of @((int)evaluationDetail.Grade.Value))</small>
                                }
                             </div>
                                @Html.Raw(evaluationDetail.Description)
                        </text>
                    </td>
                    <td class="col2" valign='top'>
                         @{
                SelectList ratingList;
                List<Qu.SeniorProject.Model.CriteriaRating> ratings;
                
                if (evaluationDetail.IsForGrading)
                {
                    ratings = ViewBag.Ratings;
                }
                else
                {
                    ratings = ViewBag.RatingsForCourseAssessment;
                }
                        
                if (evaluationDetail.RatingID != null)
                {
                    ratingList = new SelectList(ratings, "RatingID", "Description", evaluationDetail.RatingID.Value);
                                 @Html.DropDownList(evaluationDetail.EvaluationItemID, ratingList, requiredField);
                }
                else
                {
                    ratingList = new SelectList(ratings, "RatingID", "Description");
                                 @Html.DropDownList(evaluationDetail.EvaluationItemID, ratingList, "", requiredField);
                }
                         }
  
                         @* @Html.DropDownList(evaluationDetail.EvaluationItemID, ratingList)
                           , (evaluationDetail.RatingID == null ? "" : (string)ViewBag.Ratings[evaluationDetail.RatingID.Value-1].Description))*@
                    </td>
                    <td class="col3" align='justify'>
                        @Html.TextArea("Comment-" + evaluationDetail.EvaluationItemID,
                        evaluationDetail.Comments,
                        new Dictionary<string, object>
                          {
                             {"class", "textBoxStyle"}
                          })
                    </td>
                </tr>
        }
  }


  @helper DisplayGradingFooter(bool isExaminationTime)
      {
          
          var htmpAttributes = new Dictionary<string, object>();
          htmpAttributes.Add("minlength", "100");

          if (isExaminationTime)
          {
              htmpAttributes.Add("class", "required");
          }
          
       <table class="table">
       <tr>
            <td colspan="3" style="font-weight: bold; color: #800000;">
               <em>*</em>Please enter comments and feedback for students to consider (this is a mandatory field - minimum 100 characters):
            </td>
        </tr>
        <tr>
            <td colspan="3" align='justify'>
                @Html.TextArea("overallComment", (string)ViewBag.OverallComment, htmpAttributes)
            </td>
       </tr>


       @if (ViewBag.ProjectSummary != null && ((string)ViewBag.ProjectSummary.Role == "Examiner" || (string)ViewBag.ProjectSummary.Role == "SecondExaminer"))
       {
           string isChecked = string.Empty;
           string checkBoxName = (ViewBag.ProjectSummary.Role == "Examiner" ? "IsNominatedByExaminer1" : "IsNominatedByExaminer2");
           if ((bool)ViewBag.ProjectSummary.IsNominatedByExaminer1 && ViewBag.ProjectSummary.Role == "Examiner")
           {
               isChecked = "checked='yes'";
           }

           if ((bool)ViewBag.ProjectSummary.IsNominatedByExaminer2 && ViewBag.ProjectSummary.Role == "SecondExaminer")
           {
               isChecked = "checked='yes'";
           }
            
               <tr>
                   <td colspan="3" align='justify'>
                        <INPUT TYPE=CHECKBOX NAME="@checkBoxName" @isChecked><b style="color:Maroon;">Tick to nominate this project for the Senior Project Award</b>
                   </td>
               </tr>
       }

       <tr>
           <td colspan="2" align="center">
               <p>
                    <input type="submit" value="Submit" id="submitButton"/>
                </p>
           </td>
           <td align='right'>
              <a href="#" onClick="history.go(-1); return false;">Back to My Projects</a> 
               @* @Html.ActionLink("Back to My Projects", "Index", "Home")*@
           </td>
       </tr>
    </table>
  }


  @helper DisplayProjectSummary()
      {
                        //Project Summary Table
    <table class="table">
            <tr>
                <td class="tdProjectSummary">
                    ProjectID: 
                </td>
                <td>
                    @ViewBag.ProjectSummary.ProjectID
                </td>
                <td class="tdProjectSummary">
                    Project Title: 
                </td>
                <td>   
                    @ViewBag.ProjectSummary.Title
                </td>
            </tr>
            <tr>
                <td class="tdProjectSummary">
                    Students:
                </td>
                <td> 
                    @Html.Raw(ViewBag.ProjectSummary.Students)
                </td>
                <td class="tdProjectSummary">
                   Section: 
               </td>
                <td>
                  @ViewBag.ProjectSummary.Major 
                 </td>
            </tr>
           @* <tr>
                <td class="tdProjectSummary">
                    Supervisors:
                </td>
                <td colspan="3"> 
                    @Html.Raw(ViewBag.ProjectSummary.Supervisors)
                </td>
                <td class="tdProjectSummary">
                    Proposal Examiner: 
                </td>
                <td> 
                    @ViewBag.ProjectSummary.ProposalExaminer
                 </td>
            </tr>*@
    </table>
  }